package zihua.lee.sdk;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zihua.lee.sdk.domain.service.Impl.OpenAiCodeReviewService;
import zihua.lee.sdk.infrastructure.git.GitCommand;
import zihua.lee.sdk.infrastructure.openai.IOpenAI;
import zihua.lee.sdk.infrastructure.openai.impl.ChatGLM;
import zihua.lee.sdk.infrastructure.weixin.WeiXin;

/**
 * \* User: 木辛桦
 * \* gitee:https://gitee.com/lzfa7
 * \* Date: 2024/9/10
 * \* Time: 21:12
 * \* Description:
 * \
 */


public class OpenAiCodeReview {
    private static final Logger logger = LoggerFactory.getLogger(OpenAiCodeReview.class);

    public static void main(String[] args) throws Exception {
        GitCommand gitCommand = new GitCommand(
                getEnv("GITHUB_REVIEW_LOG_URI"),
                getEnv("GITHUB_TOKEN"),
                getEnv("COMMIT_PROJECT"),
                getEnv("COMMIT_BRANCH"),
                getEnv("COMMIT_AUTHOR"),
                getEnv("COMMIT_MESSAGE")
        );

        /**
         * 项目：{{repo_name.DATA}} 分支：{{branch_name.DATA}} 作者：{{commit_author.DATA}} 说明：{{commit_message.DATA}}
         */
        WeiXin weiXin = new WeiXin(
                getEnv("WEIXIN_APPID"),
                getEnv("WEIXIN_SECRET"),
                getEnv("WEIXIN_TOUSER"),
                getEnv("WEIXIN_TEMPLATE_ID")

        );



        IOpenAI openAI = new ChatGLM(getEnv("CHATGLM_APIHOST"), getEnv("CHATGLM_APIKEYSECRET"));

        OpenAiCodeReviewService openAiCodeReviewService = new OpenAiCodeReviewService(gitCommand, openAI, weiXin);
        openAiCodeReviewService.exec();

        logger.info("openai-code-review done!");
    }

    private static String getEnv(String key) {
        String value = System.getenv(key);
        System.out.println("value:"+value);
        if (null == value || value.isEmpty()) {
            throw new RuntimeException("value is null");
        }
        return value;
    }

}
